'use strict';

const path = require('path');

module.exports = appInfo => {
  const config = exports = {
    security: {
      csrf: false,
    },
    middleware: ['authHandler', 'errorHandler'],
    view: {
      root: path.join(appInfo.baseDir, 'app/view'),
      mapping: {
        '.html': 'nunjucks',
      },
    },
    session: {
      renew: true
    }
  };

  config.keys = appInfo.name + '_1566870744611_6975';

  config.assets = {
    publicPath: '/public',
    devServer: {
      autoPort: true,
      command: 'umi dev --port={port}',
      env: {
        APP_ROOT: process.cwd() + '/app/web',
        BROWSER: 'none',
        SOCKET_SERVER: 'http://127.0.0.1:{port}',
      },
      debug: false,
    },
  };

  config.grpc = {
    // endpoint: '192.168.1.206:10114',
    endpoints: {
      'com.jstide.grpc.user.userService': '192.168.1.206:10114',
      'com.jstide.grpc.dictionary.scndDicConfigService': '192.168.1.206:10115'
    },
    dir: 'app/proto', // proto files dir, relative path
    // property: 'grpc', // default attach to `ctx.grpc.**`
    // loadOpts: { convertFieldsToCamelCase: true, }, // message field case: `string user_name` -> `userName`
  };

  config.errorHandler = {
    match: '/api'
  }

  config.authHandler = {
    // match: '/api',
    ignore: ['/', '/api/login', '/api/logout']
  }

  // config.redis = {
  //   client: {
  //     host: '127.0.0.1',
  //     port: 6379,
  //     password: '',
  //     db: '0',
  //   },
  //   agent: true
  // }

  config.onerror = {
    json(err, ctx) {
      ctx.body = err;
      ctx.status = 500;
    }
  }

  return config
};